/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.com;

/**
 *
 * @author romulogalindo
 */
public class Util {

    public static int convertir_entero(Object valor) {
        return convertir_entero(valor, 0);
    }

    public static int convertir_entero(Object valor, int defecto) {
        int retorno = defecto;

        String valor2 = ("" + valor).trim();
        if (valor2.length() > 0) {
            try {
                retorno = Integer.parseInt(valor2);
            } catch (Exception ep) {
                retorno = defecto;
            }
        } else {
            retorno = defecto;
        }
        return retorno;
    }

    public static double convertir_double(Object valor) {
        return convertir_double(valor, 0);
    }

    public static double convertir_double(Object valor, double defecto) {
        double retorno;

        String valor2 = ("" + valor).trim();
        if (valor2.length() > 0) {
            try {
                retorno = Double.parseDouble(valor2);
            } catch (NumberFormatException ep) {
                System.out.println("Error de conversion:" + ep.getMessage());
                retorno = defecto;
            }
        } else {
            retorno = defecto;
        }
        return retorno;
    }

}
